package com.ymm.system.core.testController;

import com.ymm.system.api.constants.CargoEntity;
import com.ymm.system.api.dto.*;
import com.ymm.system.api.facade.*;
import com.ymm.system.api.utils.Result;
import com.ymm.system.core.facade.SystemGenerateOrderTradeServiceImpl;
import com.ymm.system.core.facade.SystemShipperOrderServiceImpl;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @Author zikang.yao
 * @Description TODO
 * @Date 2022/8/4 10:32
 * @Version 1.0
 */
@RestController
@RequestMapping("system")
public class TestController {

    @Autowired
    private SystemDisplayService systemDisplayService;

    @Autowired
    private SystemGenerateOrderTradeServiceImpl systemGenerateOrderTradeService;

    @Autowired
    private SystemShipperOrderServiceImpl systemShipperOrderService;

    @Autowired
    private SystemMatchService systemMatchService;

    @Autowired
    private SystemDriverOrderTradeService systemDriverOrderTradeService;

    @Autowired
    private SystemCargoService systemCargoService;

    @Autowired
    private SystemOrderService systemOrderService;

    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping("/test1")
        public Result<List<CargoDTO>> test(){
      //  List<OrderShowDTO> orderShowDTOList = systemDisplayService.searchOrderDetailByPage();
   //     return orderShowDTOList.size();
    //    return systemShipperOrderService.listOrderDetailByReceiverPhone("14433331111");
//        return systemMatchService.driverSearchSpecifyTimeCargoService(31.99, 118.78,
//                3, new Date(), new Date(2222,12,23,1,4,6));
    //    return systemDriverOrderTradeService.getLltorderDetailsDTO(8L);
     //   return systemDisplayService.searchOrderDetails();
     //   return systemMatchService.PushLongTimeCargo(31.99, 118.78, 3);
        return systemMatchService.PushLongTimeCargo(31.99, 118.78, 4, 3L);
    }

    @RequestMapping("/test2")
    public void test2(){

        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("name", "张洪源");
        HashOperations<String, String, String> hashOperations = redisTemplate.opsForHash();
        String o = hashOperations.get("1L","5L");
        if (o == null)
            valueOperations.set("name2", "null");
        else
            valueOperations.set("name2", o);
        //  List<OrderShowDTO> orderShowDTOList = systemDisplayService.searchOrderDetailByPage();
        //     return orderShowDTOList.size();

//        DriverGrabDTO driverGrabDTO = new DriverGrabDTO();
//        driverGrabDTO.setDriverId(1L);
//        driverGrabDTO.setCargoId(75L);
//        driverGrabDTO.setDriverLocation("南京");
//        systemGenerateOrderTradeService.generateOrder(driverGrabDTO);
//
//        systemOrderService.confirmReceipt(74L, 3, null);
//        PutOnCargoRequest putOnCargoRequest = new PutOnCargoRequest();
//        putOnCargoRequest.setCargoDesLon(BigDecimal.valueOf(129.99));
//        putOnCargoRequest.setCargoDesLat(BigDecimal.valueOf(30.2));
//        putOnCargoRequest.setCargoSrcLon(BigDecimal.valueOf(121.99));
//        putOnCargoRequest.setCargoSrcLat(BigDecimal.valueOf(31.2));
//        putOnCargoRequest.setCargoDesCity("asd");
//        putOnCargoRequest.setCargoDes("cddd");
//        putOnCargoRequest.setShipperId(12L);
//        putOnCargoRequest.setCargoSrc("asd");
//        putOnCargoRequest.setCargoSrcProv("asd");
//        putOnCargoRequest.setCargoSrcRegion("aasd");
//        putOnCargoRequest.setCargoSrcCity("asd");
//        putOnCargoRequest.setCargoDesProv("asd");
//        putOnCargoRequest.setCargoDesCity("asd");
//        putOnCargoRequest.setCargoDesRegion("das");
//        putOnCargoRequest.setCargoDescription("asd");
//        putOnCargoRequest.setCargoDeliveryTime(new Date());
//        putOnCargoRequest.setCargoPrice(123);
//        putOnCargoRequest.setCargoReceiverPhone("asd");
//        putOnCargoRequest.setCargoShipperPhone("asdasf");
//        putOnCargoRequest.setCargoType(3);
//        putOnCargoRequest.setCargoRequireType(3);
//        systemCargoService.cargoDeliver(putOnCargoRequest, null, null);

    }

    @RequestMapping("/test3")
    public void test3(){
        DriverGrabDTO driverGrabDTO = new DriverGrabDTO();
        driverGrabDTO.setDriverLocation("南京市");
        driverGrabDTO.setDriverId(2L);
        driverGrabDTO.setCargoId(78L);
        systemGenerateOrderTradeService.generateOrder(driverGrabDTO);
    }

    @RequestMapping("/test4")
    public void test4(){
        DriverGrabDTO driverGrabDTO = new DriverGrabDTO();
        driverGrabDTO.setDriverLocation("南京市");
        driverGrabDTO.setDriverId(3L);
        driverGrabDTO.setCargoId(78L);
        systemGenerateOrderTradeService.generateOrder(driverGrabDTO);
    }
}
